home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / modes / icon.el.z / icon.el
Encoding:
Text File  |  1998-05-21  |  20.0 KB  |  577 lines

  1. ;;; icon.el --- mode for editing Icon code
  2.  
  3. ;; Copyright (C) 1989 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Chris Smith <csmith@convex.com>
  6. ;; Created: 15 Feb 89
  7. ;; Keywords: languages
  8.  
  9. ;; This file is part of XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  23. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. ;; 02111-1307, USA.
  25.  
  26. ;;; Synched up with: FSF 19.34.
  27.  
  28. ;;; Commentary:
  29.  
  30. ;; A major mode for editing the Icon programming language.
  31.  
  32. ;;; Code:
  33.  
  34. (defvar icon-mode-abbrev-table nil
  35.   "Abbrev table in use in Icon-mode buffers.")
  36. (define-abbrev-table 'icon-mode-abbrev-table ())
  37.  
  38. (defvar icon-mode-map ()
  39.   "Keymap used in Icon mode.")
  40. (if icon-mode-map
  41.     ()
  42.   (setq icon-mode-map (make-sparse-keymap))
  43.   (define-key icon-mode-map "{" 'electric-icon-brace)
  44.   (define-key icon-mode-map "}" 'electric-icon-brace)
  45.   (define-key icon-mode-map "\e\C-h" 'mark-icon-function)
  46.   (define-key icon-mode-map "\e\C-a" 'beginning-of-icon-defun)
  47.   (define-key icon-mode-map "\e\C-e" 'end-of-icon-defun)
  48.   (define-key icon-mode-map "\e\C-q" 'indent-icon-exp)
  49.   (define-key icon-mode-map "\t" 'icon-indent-command))
  50.  
  51. (defvar icon-mode-syntax-table nil
  52.   "Syntax table in use in Icon-mode buffers.")
  53.  
  54. (if icon-mode-syntax-table
  55.     ()
  56.   (setq icon-mode-syntax-table (make-syntax-table))
  57.   (modify-syntax-entry ?\\ "\\" icon-mode-syntax-table)
  58.   (modify-syntax-entry ?# "<" icon-mode-syntax-table)
  59.   (modify-syntax-entry ?\n ">" icon-mode-syntax-table)
  60.   (modify-syntax-entry ?$ "." icon-mode-syntax-table)
  61.   (modify-syntax-entry ?/ "." icon-mode-syntax-table)
  62.   (modify-syntax-entry ?* "." icon-mode-syntax-table)
  63.   (modify-syntax-entry ?+ "." icon-mode-syntax-table)
  64.   (modify-syntax-entry ?- "." icon-mode-syntax-table)
  65.   (modify-syntax-entry ?= "." icon-mode-syntax-table)
  66.   (modify-syntax-entry ?% "." icon-mode-syntax-table)
  67.   (modify-syntax-entry ?< "." icon-mode-syntax-table)
  68.   (modify-syntax-entry ?> "." icon-mode-syntax-table)
  69.   (modify-syntax-entry ?& "." icon-mode-syntax-table)
  70.   (modify-syntax-entry ?| "." icon-mode-syntax-table)
  71.   (modify-syntax-entry ?\' "\"" icon-mode-syntax-table))
  72.  
  73. (defgroup icon nil
  74.   "Mode for editing icon code."
  75.   :group 'languages)
  76.  
  77.  
  78. (defcustom icon-indent-level 4
  79.   "*Indentation of Icon statements with respect to containing block."
  80.   :type 'integer
  81.   :group 'icon)
  82. (defcustom icon-brace-imaginary-offset 0
  83.   "*Imagined indentation of a Icon open brace that actually follows a statement."
  84.   :type 'integer
  85.   :group 'icon)
  86. (defcustom icon-brace-offset 0
  87.   "*Extra indentation for braces, compared with other text in same context."
  88.   :type 'integer
  89.   :group 'icon)
  90. (defcustom icon-continued-statement-offset 4
  91.   "*Extra indent for lines not starting new statements."
  92.   :type 'integer
  93.   :group 'icon)
  94. (defcustom icon-continued-brace-offset 0
  95.   "*Extra indent for substatements that start with open-braces.
  96. This is in addition to icon-continued-statement-offset."
  97.   :type 'integer
  98.   :group 'icon)
  99.  
  100. (defcustom icon-auto-newline nil
  101.   "*Non-nil means automatically newline before and after braces
  102. inserted in Icon code."
  103.   :type 'boolean
  104.   :group 'icon)
  105.  
  106. (defcustom icon-tab-always-indent t
  107.   "*Non-nil means TAB in Icon mode should always reindent the current line,
  108. regardless of where in the line point is when the TAB command is used."
  109.   :type 'integer
  110.   :group 'icon)
  111.  
  112. ;;;###autoload
  113. (defun icon-mode ()
  114.   "Major mode for editing Icon code.
  115. Expression and list commands understand all Icon brackets.
  116. Tab indents for Icon code.
  117. Paragraphs are separated by blank lines only.
  118. Delete converts tabs to spaces as it moves back.
  119. \\{icon-mode-map}
  120. Variables controlling indentation style:
  121.  icon-tab-always-indent
  122.     Non-nil means TAB in Icon mode should always reindent the current line,
  123.     regardless of where in the line point is when the TAB command is used.
  124.  icon-auto-newline
  125.     Non-nil means automatically newline before and after braces
  126.     inserted in Icon code.
  127.  icon-indent-level
  128.     Indentation of Icon statements within surrounding block.
  129.     The surrounding block's indentation is the indentation
  130.     of the line on which the open-brace appears.
  131.  icon-continued-statement-offset
  132.     Extra indentation given to a substatement, such as the
  133.     then-clause of an if or body of a while.
  134.  icon-continued-brace-offset
  135.     Extra indentation given to a brace that starts a substatement.
  136.     This is in addition to `icon-continued-statement-offset'.
  137.  icon-brace-offset
  138.     Extra indentation for line if it starts with an open brace.
  139.  icon-brace-imaginary-offset
  140.     An open brace following other text is treated as if it were
  141.     this far to the right of the start of its line.
  142.  
  143. Turning on Icon mode calls the value of the variable `icon-mode-hook'
  144. with no args, if that value is non-nil."
  145.   (interactive)
  146.   (kill-all-local-variables)
  147.   (use-local-map icon-mode-map)
  148.   (setq major-mode 'icon-mode)
  149.   (setq mode-name "Icon")
  150.   (setq local-abbrev-table icon-mode-abbrev-table)
  151.   (set-syntax-table icon-mode-syntax-table)
  152.   (make-local-variable 'paragraph-start)
  153.   (setq paragraph-start (concat "$\\|" page-delimiter))
  154.   (make-local-variable 'paragraph-separate)
  155.   (setq paragraph-separate paragraph-start)
  156.   (make-local-variable 'indent-line-function)
  157.   (setq indent-line-function 'icon-indent-line)
  158.   (make-local-variable 'require-final-newline)
  159.   (setq require-final-newline t)
  160.   (make-local-variable 'comment-start)
  161.   (setq comment-start "# ")
  162.   (make-local-variable 'comment-end)
  163.   (setq comment-end "")
  164.   (make-local-variable 'comment-column)
  165.   (setq comment-column 32)
  166.   (make-local-variable 'comment-start-skip)
  167.   (setq comment-start-skip "# *")
  168.   (make-local-variable 'comment-indent-function)
  169.   (setq comment-indent-function 'icon-comment-indent)
  170.   (run-hooks 'icon-mode-hook))
  171.  
  172. ;; This is used by indent-for-comment to decide how much to
  173. ;; indent a comment in Icon code based on its context.
  174. (defun icon-comment-indent ()
  175.   (if (looking-at "^#")
  176.       0    
  177.     (save-excursion
  178.       (skip-chars-backward " \t")
  179.       (max (if (bolp) 0 (1+ (current-column)))
  180.        comment-column))))
  181.  
  182. (defun electric-icon-brace (arg)
  183.   "Insert character and correct line's indentation."
  184.   (interactive "P")
  185.   (let (insertpos)
  186.     (if (and (not arg)
  187.          (eolp)
  188.          (or (save-excursion
  189.            (skip-chars-backward " \t")
  190.            (bolp))
  191.          (if icon-auto-newline
  192.              (progn (icon-indent-line) (newline) t)
  193.            nil)))
  194.     (progn
  195.       (insert last-command-char)
  196.       (icon-indent-line)
  197.       (if icon-auto-newline
  198.           (progn
  199.         (newline)
  200.         ;; (newline) may have done auto-fill
  201.         (setq insertpos (- (point) 2))
  202.         (icon-indent-line)))
  203.       (save-excursion
  204.         (if insertpos (goto-char (1+ insertpos)))
  205.         (delete-char -1))))
  206.     (if insertpos
  207.     (save-excursion
  208.       (goto-char insertpos)
  209.       (self-insert-command (prefix-numeric-value arg)))
  210.       (self-insert-command (prefix-numeric-value arg)))))
  211.  
  212. (defun icon-indent-command (&optional whole-exp)
  213.   (interactive "P")
  214.   "Indent current line as Icon code, or in some cases insert a tab character.
  215. If `icon-tab-always-indent' is non-nil (the default), always indent current
  216. line.  Otherwise, indent the current line only if point is at the left margin
  217. or in the line's indentation; otherwise insert a tab.
  218.  
  219. A numeric argument, regardless of its value, means indent rigidly all the
  220. lines of the expression starting after point so that this line becomes
  221. properly indented.  The relative indentation among the lines of the
  222. expression are preserved."
  223.   (if whole-exp
  224.       ;; If arg, always indent this line as Icon
  225.       ;; and shift remaining lines of expression the same amount.
  226.       (let ((shift-amt (icon-indent-line))
  227.         beg end)
  228.     (save-excursion
  229.       (if icon-tab-always-indent
  230.           (beginning-of-line))
  231.       (setq beg (point))
  232.       (forward-sexp 1)
  233.       (setq end (point))
  234.       (goto-char beg)
  235.       (forward-line 1)
  236.       (setq beg (point)))
  237.     (if (> end beg)
  238.         (indent-code-rigidly beg end shift-amt "#")))
  239.     (if (and (not icon-tab-always-indent)
  240.          (save-excursion
  241.            (skip-chars-backward " \t")
  242.            (not (bolp))))
  243.     (insert-tab)
  244.       (icon-indent-line))))
  245.  
  246. (defun icon-indent-line ()
  247.   "Indent current line as Icon code.
  248. Return the amount the indentation changed by."
  249.   (let ((indent (calculate-icon-indent nil))
  250.     beg shift-amt
  251.     (case-fold-search nil)
  252.     (pos (- (point-max) (point))))
  253.     (beginning-of-line)
  254.     (setq beg (point))
  255.     (cond ((eq indent nil)
  256.        (setq indent (current-indentation)))
  257.       ((eq indent t)
  258.        (setq indent (calculate-icon-indent-within-comment)))
  259.       ((looking-at "[ \t]*#")
  260.        (setq indent 0))
  261.       (t
  262.        (skip-chars-forward " \t")
  263.        (if (listp indent) (setq indent (car indent)))
  264.        (cond ((and (looking-at "else\\b")
  265.                (not (looking-at "else\\s_")))
  266.           (setq indent (save-excursion
  267.                  (icon-backward-to-start-of-if)
  268.                  (current-indentation))))
  269.          ((or (= (following-char) ?})
  270.               (looking-at "end\\b"))
  271.           (setq indent (- indent icon-indent-level)))
  272.          ((= (following-char) ?{)
  273.           (setq indent (+ indent icon-brace-offset))))))
  274.     (skip-chars-forward " \t")
  275.     (setq shift-amt (- indent (current-column)))
  276.     (if (zerop shift-amt)
  277.     (if (> (- (point-max) pos) (point))
  278.         (goto-char (- (point-max) pos)))
  279.       (delete-region beg (point))
  280.       (indent-to indent)
  281.       ;; If initial point was within line's indentation,
  282.       ;; position after the indentation.  Else stay at same point in text.
  283.       (if (> (- (point-max) pos) (point))
  284.       (goto-char (- (point-max) pos))))
  285.     shift-amt))
  286.  
  287. (defun calculate-icon-indent (&optional parse-start)
  288.   "Return appropriate indentation for current line as Icon code.
  289. In usual case returns an integer: the column to indent to.
  290. Returns nil if line starts inside a string, t if in a comment."
  291.   (save-excursion
  292.     (beginning-of-line)
  293.     (let ((indent-point (point))
  294.       (case-fold-search nil)
  295.       state
  296.       containing-sexp
  297.       toplevel)
  298.       (if parse-start
  299.       (goto-char parse-start)
  300.     (setq toplevel (beginning-of-icon-defun)))
  301.       (while (< (point) indent-point)
  302.     (setq parse-start (point))
  303.     (setq state (parse-partial-sexp (point) indent-point 0))
  304.     (setq containing-sexp (car (cdr state))))
  305.       (cond ((or (nth 3 state) (nth 4 state))
  306.          ;; return nil or t if should not change this line
  307.          (nth 4 state))
  308.         ((and containing-sexp
  309.           (/= (char-after containing-sexp) ?{))
  310.          ;; line is expression, not statement:
  311.          ;; indent to just after the surrounding open.
  312.          (goto-char (1+ containing-sexp))
  313.          (current-column))
  314.         (t
  315.           (if toplevel
  316.           ;; Outside any procedures.
  317.           (progn (icon-backward-to-noncomment (point-min))
  318.              (if (icon-is-continuation-line)
  319.                  icon-continued-statement-offset 0))
  320.         ;; Statement level.
  321.         (if (null containing-sexp)
  322.             (progn (beginning-of-icon-defun)
  323.                (setq containing-sexp (point))))
  324.         (goto-char indent-point)
  325.         ;; Is it a continuation or a new statement?
  326.         ;; Find previous non-comment character.
  327.         (icon-backward-to-noncomment containing-sexp)
  328.         ;; Now we get the answer.
  329.         (if (icon-is-continuation-line)
  330.             ;; This line is continuation of preceding line's statement;
  331.             ;; indent  icon-continued-statement-offset  more than the
  332.             ;; first line of the statement.
  333.             (progn
  334.               (icon-backward-to-start-of-continued-exp containing-sexp)
  335.               (+ icon-continued-statement-offset (current-column)
  336.              (if (save-excursion (goto-char indent-point)
  337.                          (skip-chars-forward " \t")
  338.                          (eq (following-char) ?{))
  339.                  icon-continued-brace-offset 0)))
  340.           ;; This line starts a new statement.
  341.           ;; Position following last unclosed open.
  342.           (goto-char containing-sexp)
  343.           ;; Is line first statement after an open-brace?
  344.           (or
  345.             ;; If no, find that first statement and indent like it.
  346.             (save-excursion
  347.               (if (looking-at "procedure\\s ")
  348.               (forward-sexp 3)
  349.             (forward-char 1))
  350.               (while (progn (skip-chars-forward " \t\n")
  351.                     (looking-at "#"))
  352.             ;; Skip over comments following openbrace.
  353.             (forward-line 1))
  354.               ;; The first following code counts
  355.               ;; if it is before the line we want to indent.
  356.               (and (< (point) indent-point)
  357.                (current-column)))
  358.             ;; If no previous statement,
  359.             ;; indent it relative to line brace is on.
  360.             ;; For open brace in column zero, don't let statement
  361.             ;; start there too.  If icon-indent-level is zero,
  362.             ;; use icon-brace-offset + icon-continued-statement-offset
  363.             ;; instead.
  364.             ;; For open-braces not the first thing in a line,
  365.             ;; add in icon-brace-imaginary-offset.
  366.             (+ (if (and (bolp) (zerop icon-indent-level))
  367.                (+ icon-brace-offset
  368.                   icon-continued-statement-offset)
  369.              icon-indent-level)
  370.                ;; Move back over whitespace before the openbrace.
  371.                ;; If openbrace is not first nonwhite thing on the line,
  372.                ;; add the icon-brace-imaginary-offset.
  373.                (progn (skip-chars-backward " \t")
  374.                   (if (bolp) 0 icon-brace-imaginary-offset))
  375.                ;; Get initial indentation of the line we are on.
  376.                (current-indentation))))))))))
  377.  
  378. ;; List of words to check for as the last thing on a line.
  379. ;; If cdr is t, next line is a continuation of the same statement,
  380. ;; if cdr is nil, next line starts a new (possibly indented) statement.
  381.  
  382. (defconst icon-resword-alist
  383.   '(("by" . t) ("case" . t) ("create") ("do") ("dynamic" . t) ("else")
  384.     ("every" . t) ("if" . t) ("global" . t) ("initial" . t)
  385.     ("link" . t) ("local" . t) ("of") ("record" . t) ("repeat" . t)
  386.     ("static" . t) ("then") ("to" . t) ("until" . t) ("while" . t)))
  387.  
  388. (defun icon-is-continuation-line ()
  389.   (let* ((ch (preceding-char))
  390.      (ch-syntax (char-syntax ch)))
  391.     (if (eq ch-syntax ?w)
  392.     (assoc (buffer-substring
  393.         (progn (forward-word -1) (point))
  394.         (progn (forward-word 1) (point)))
  395.            icon-resword-alist)
  396.       (not (memq ch '(0 ?\; ?\} ?\{ ?\) ?\] ?\" ?\' ?\n))))))
  397.  
  398. (defun icon-backward-to-noncomment (lim)
  399.   (let (opoint stop)
  400.     (while (not stop)
  401.       (skip-chars-backward " \t\n\f" lim)
  402.       (setq opoint (point))
  403.       (beginning-of-line)
  404.       (if (and (nth 5 (parse-partial-sexp (point) opoint))
  405.            (< lim (point)))
  406.       (search-backward "#")
  407.     (setq stop t)))))
  408.  
  409. (defun icon-backward-to-start-of-continued-exp (lim)
  410.   (if (memq (preceding-char) '(?\) ?\]))
  411.       (forward-sexp -1))
  412.   (beginning-of-line)
  413.   (skip-chars-forward " \t")
  414.   (cond
  415.    ((<= (point) lim) (goto-char (1+ lim)))
  416.    ((not (icon-is-continued-line)) 0)
  417.    ((and (eq (char-syntax (following-char)) ?w)
  418.      (cdr
  419.       (assoc (buffer-substring (point)
  420.                    (save-excursion (forward-word 1) (point)))
  421.          icon-resword-alist))) 0)
  422.    (t (end-of-line 0) (icon-backward-to-start-of-continued-exp lim))))
  423.  
  424. (defun icon-is-continued-line ()
  425.   (save-excursion
  426.     (end-of-line 0)
  427.     (icon-is-continuation-line)))
  428.  
  429. (defun icon-backward-to-start-of-if (&optional limit)
  430.   "Move to the start of the last \"unbalanced\" if."
  431.   (or limit (setq limit (save-excursion (beginning-of-icon-defun) (point))))
  432.   (let ((if-level 1)
  433.     (case-fold-search nil))
  434.     (while (not (zerop if-level))
  435.       (backward-sexp 1)
  436.       (cond ((looking-at "else\\b")
  437.          (setq if-level (1+ if-level)))
  438.         ((looking-at "if\\b")
  439.          (setq if-level (1- if-level)))
  440.         ((< (point) limit)
  441.          (setq if-level 0)
  442.          (goto-char limit))))))
  443.  
  444. (defun mark-icon-function ()
  445.   "Put mark at end of Icon function, point at beginning."
  446.   (interactive)
  447.   (push-mark (point))
  448.   (end-of-icon-defun)
  449.   (push-mark (point))
  450.   (beginning-of-line 0)
  451.   (beginning-of-icon-defun))
  452.  
  453. (defun beginning-of-icon-defun ()
  454.   "Go to the start of the enclosing procedure; return t if at top level."
  455.   (interactive)
  456.   (if (re-search-backward "^procedure\\s \\|^end[ \t\n]" (point-min) 'move)
  457.       (looking-at "e")
  458.     t))
  459.  
  460. (defun end-of-icon-defun ()
  461.   (interactive)
  462.   (if (not (bobp)) (forward-char -1))
  463.   (re-search-forward "\\(\\s \\|^\\)end\\(\\s \\|$\\)" (point-max) 'move)
  464.   (forward-word -1)
  465.   (forward-line 1))
  466.  
  467. (defun indent-icon-exp ()
  468.   "Indent each line of the Icon grouping following point."
  469.   (interactive)
  470.   (let ((indent-stack (list nil))
  471.     (contain-stack (list (point)))
  472.     (case-fold-search nil)
  473.     restart outer-loop-done inner-loop-done state ostate
  474.     this-indent last-sexp
  475.     at-else at-brace at-do
  476.     (opoint (point))
  477.     (next-depth 0))
  478.     (save-excursion
  479.       (forward-sexp 1))
  480.     (save-excursion
  481.       (setq outer-loop-done nil)
  482.       (while (and (not (eobp)) (not outer-loop-done))
  483.     (setq last-depth next-depth)
  484.     ;; Compute how depth changes over this line
  485.     ;; plus enough other lines to get to one that
  486.     ;; does not end inside a comment or string.
  487.     ;; Meanwhile, do appropriate indentation on comment lines.
  488.     (setq innerloop-done nil)
  489.     (while (and (not innerloop-done)
  490.             (not (and (eobp) (setq outer-loop-done t))))
  491.       (setq ostate state)
  492.       (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
  493.                       nil nil state))
  494.       (setq next-depth (car state))
  495.       (if (and (car (cdr (cdr state)))
  496.            (>= (car (cdr (cdr state))) 0))
  497.           (setq last-sexp (car (cdr (cdr state)))))
  498.       (if (or (nth 4 ostate))
  499.           (icon-indent-line))
  500.       (if (or (nth 3 state))
  501.           (forward-line 1)
  502.         (setq innerloop-done t)))
  503.     (if (<= next-depth 0)
  504.         (setq outer-loop-done t))
  505.     (if outer-loop-done
  506.         nil
  507.       (if (/= last-depth next-depth)
  508.           (setq last-sexp nil))
  509.       (while (> last-depth next-depth)
  510.         (setq indent-stack (cdr indent-stack)
  511.           contain-stack (cdr contain-stack)
  512.           last-depth (1- last-depth)))
  513.       (while (< last-depth next-depth)
  514.         (setq indent-stack (cons nil indent-stack)
  515.           contain-stack (cons nil contain-stack)
  516.           last-depth (1+ last-depth)))
  517.       (if (null (car contain-stack))
  518.           (setcar contain-stack (or (car (cdr state))
  519.                     (save-excursion (forward-sexp -1)
  520.                             (point)))))
  521.       (forward-line 1)
  522.       (skip-chars-forward " \t")
  523.       (if (eolp)
  524.           nil
  525.         (if (and (car indent-stack)
  526.              (>= (car indent-stack) 0))
  527.         ;; Line is on an existing nesting level.
  528.         ;; Lines inside parens are handled specially.
  529.         (if (/= (char-after (car contain-stack)) ?{)
  530.             (setq this-indent (car indent-stack))
  531.           ;; Line is at statement level.
  532.           ;; Is it a new statement?  Is it an else?
  533.           ;; Find last non-comment character before this line
  534.           (save-excursion
  535.             (setq at-else (looking-at "else\\W"))
  536.             (setq at-brace (= (following-char) ?{))
  537.             (icon-backward-to-noncomment opoint)
  538.             (if (icon-is-continuation-line)
  539.             ;; Preceding line did not end in comma or semi;
  540.             ;; indent this line  icon-continued-statement-offset
  541.             ;; more than previous.
  542.             (progn
  543.               (icon-backward-to-start-of-continued-exp (car contain-stack))
  544.               (setq this-indent
  545.                 (+ icon-continued-statement-offset (current-column)
  546.                    (if at-brace icon-continued-brace-offset 0))))
  547.               ;; Preceding line ended in comma or semi;
  548.               ;; use the standard indent for this level.
  549.               (if at-else
  550.               (progn (icon-backward-to-start-of-if opoint)
  551.                  (setq this-indent (current-indentation)))
  552.             (setq this-indent (car indent-stack))))))
  553.           ;; Just started a new nesting level.
  554.           ;; Compute the standard indent for this level.
  555.           (let ((val (calculate-icon-indent
  556.                (if (car indent-stack)
  557.                    (- (car indent-stack))))))
  558.         (setcar indent-stack
  559.             (setq this-indent val))))
  560.         ;; Adjust line indentation according to its contents
  561.         (if (or (= (following-char) ?})
  562.             (looking-at "end\\b"))
  563.         (setq this-indent (- this-indent icon-indent-level)))
  564.         (if (= (following-char) ?{)
  565.         (setq this-indent (+ this-indent icon-brace-offset)))
  566.         ;; Put chosen indentation into effect.
  567.         (or (= (current-column) this-indent)
  568.         (progn
  569.           (delete-region (point) (progn (beginning-of-line) (point)))
  570.           (indent-to this-indent)))
  571.         ;; Indent any comment following the text.
  572.         (or (looking-at comment-start-skip)
  573.         (if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
  574.             (progn (indent-for-comment) (beginning-of-line))))))))))
  575.  
  576. ;;; icon.el ends here
  577.